﻿<AuthorizeView Roles="@Roles">
    <Authorized>
        @ChildContent
    </Authorized>
    <NotAuthorized>
        <AuthorizeView>
            <Authorized Context="abc">
                <div class="text-danger">您目前登录的账号没有包含<strong>@RolesDevided</strong>角色。</div>
                <br />
                <div>请<a href="Identity/Account/Login">登录</a>包含<strong>@RolesDevided</strong>角色的账号进行操作。</div>
            </Authorized>
            <NotAuthorized Context="abc">
                <label>您未登录！请<a href="Identity/Account/Login">登录</a>后进行操作。</label>
            </NotAuthorized>
        </AuthorizeView>
    </NotAuthorized>
</AuthorizeView>

@code {
    [Parameter]
    public string Roles { get; set; }

    private string RolesDevided
    {
        get
        {
            if (string.IsNullOrEmpty(_RolesDevided))
            {
                
                string[] strs= Roles.Split(',', StringSplitOptions.RemoveEmptyEntries);
                int len = strs.Length;
                _RolesDevided = "";
                for (int i = 0; i < len - 1; i++)
                {
                    _RolesDevided += $"“{strs[i]}”或";
                }
                if (len > 0)
                {
                    _RolesDevided+=$"“{strs[len-1]}”";
                }

            }
            return _RolesDevided;
        }
    }
    private string _RolesDevided;

    [Parameter]
    public RenderFragment ChildContent { get; set; }

}
